<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 数组解构赋值的代码阅读训练

        //解构赋部分数值
        let [m, n] = [10, 20, 30];
        console.log(m); // 10
        console.log(n); // 20

        let [i, [j], k] = [10, [20, 30], 40];
        console.log(i); // 10
        console.log(j); // 20
        console.log(k); // 40

        let [x, , y] = [1, 2, 3];
        console.log(x); // 1
        console.log(y); // 3

        let [, , z] = ["one", "two", "three"];
        console.log(z); // three

        //其中...为ES6的扩展运算符，即d加上...可以接收多个值
        let [a, ...d] = [1, 2, 3, 4, 5, 6];
        console.log(a); // 1
        console.log(d); // [2,3,4,5,6]

        // 没有解构到数值的，默认为undefined，对应使用了扩展运算符的 []
        let [x1, y1, ...z1] = ['a'];
        console.log(x1); // a
        console.log(y1); // undefined
        console.log(z1); // []

        //没有接收到值得变量，默认为undefined
        let [z2] = [];  // undefined
        let [x2, y2] = [1]; //
        console.log(z2, x2, y2); //undefined 1 undefined

    </script>
</body>

</html>